import { SETMEILIST, SETGOODSLIST } from '../mutation-type'
import http from '@/utils/axios'
const module = {
  namespaced: true, // 命名空间
  state: {
    meiListNew: null,
    meiListHot: null,
    goodsList: null
  },
  actions: {
    getMeiListAction (context, payload) {
      fetch('http://www.mei.com/appapi/home/eventForH5?params=%7B%7D&timestamp=1583224233057&summary=3efd29d1e9dc4bfc9f7e951789f88f5d&platform_code=H5')
        .then(res => res.json())
        .then(res => {
          context.commit('SETMEILIST', res.lists)
        })
    },
    getGoodsListAction (context, payload) {
      http.get('/vant/goodlist').then(res => {
        context.commit('SETGOODSLIST', res.data.result)
      })
    }
  },
  mutations: {
    [SETMEILIST] (state, payload) {
      state.meiListNew = payload[0]
      state.meiListHot = payload[1]
    },
    [SETGOODSLIST] (state, payload) {
      state.goodsList = payload
    }
  },
  getters: {
    swipelist (state, getters, rootState, rootGetters) { // 属性
      if (state.meiListHot) {
        return state.meiListHot.events.map(item => item.imageUrl).slice(0, 5)
      } else {
        return null
      }
    }
  }
}

export default module
